DECLARE @Ma_DT VARCHAR(2) = N'8',
		@Ngay DATETIME = N'2014-11-19'


SELECT Madonvi,Macanbo
		,Madaily AS SoLuongDaiLy
		
		-- so luong 
		,SUM(CASE WHEN LEN( bklt.Ve5) = 2 and ISNULL(LEN( bklt.Ve10),0) <> 2 THEN 1 
		when  LEN( bklt.Ve5) <> 2 and ISNULL(LEN( bklt.Ve10),0) = 2 THEN 1 
		when  LEN( bklt.Ve5) = 2 and ISNULL(LEN( bklt.Ve10),0) = 2 THEN 2
		ELSE 0 END ) AS SoLuongVe2So
		
		
	  FROM Bangkeloto bklt
	WHERE bklt.Madonvi = @Ma_DT-- = '8'
		AND Ngaymothuong = @Ngay
		AND Madaily = '8201'
	GROUP BY Madonvi,Macanbo,Madaily
	
SELECT Madonvi,Macanbo
		,Madaily AS SoLuongDaiLy
		,VE5
		,VE10
		,LEN(VE5)
		,LEN(VE10)
	  FROM Bangkeloto bklt
	WHERE bklt.Madonvi = @Ma_DT-- = '8'
		AND Ngaymothuong = @Ngay
		AND Madaily = '8201'
	--GROUP BY Madonvi,Macanbo,Madaily